<?php

namespace Act\Logic\Event;

use Act\Logic\Event\CallBackInterface;
use \common\Table\TdSelectIdfaFromFddIosTable;
use \common\Factory\Factory;

class TdSelectIdfaFromFddIosCallback implements CallBackInterface {
    
    public function actChange($appid, $idfa, $eventTimestamp) {
        $tdSelectIdfa = new TdSelectIdfaFromFddIosTable();
        $selectResult = $tdSelectIdfa->selectIdByIdfa($idfa);
        
        if($selectResult === false) {
            $result = $tdSelectIdfa->insert(array('idfa' => $idfa));
            if($result === true) {
                Factory::getServer('MqWriteLog')->send('insert database td_select_idfa_from_fdd_ios success');
            }
            else {
                Factory::getServer('MqWriteLog')->send('insert database td_select_idfa_from_fdd_ios failed');
            }
        }
        else {
            $result = true;
            Factory::getServer('MqWriteLog')->send('insert database td_select_idfa_from_fdd_ios idfa:'. $idfa .' is exists');
        }
        
        return $result;
    }
}